package com.rcc.mongo.controller;

import com.rcc.mongo.entity.UserMongo;
import com.rcc.mongo.repository.UserMongoRepository;
import com.rcc.mongo.service.MongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by rcc on 2017/6/24.
 */
@Controller
@RequestMapping("mongo")
public class MongoController {

    @Autowired
    private MongoService mongoService;
    @Autowired
    private UserMongoRepository userMongoRepository;

    @RequestMapping("save")
    @ResponseBody
    public String save(){
        UserMongo userMongo = new UserMongo();
        userMongo.setName("张三");
        userMongo.setAge(23);
        userMongoRepository.save(userMongo);
        return "ok";
    }
    @RequestMapping("find")
    @ResponseBody
    public List<UserMongo> find(){
        return userMongoRepository.findAll();
    }

    @RequestMapping("findByName")
    @ResponseBody
    public UserMongo findByName(){
        return mongoService.findUserByName("张三");
    }
}
